/**
 * $RCSfile$
 * $Revision$
 * $Date$
 * $Source$
 * $Author$
 */
package pl.edu.agh.loganalizator.model;

/**
 * Regola okreslająca wystepowania regoly pary w relacji następstwa pierwszej wartosci
 * dodanej (setValue) po drugiej.
 * 
 * @author sadzio
 *
 */
public class PairRule extends Rule {

  private String firstString1;
  private String secondString2;
  boolean firstString;
  boolean prevMatch;
  private Row row;

  public PairRule(Column column, String value) {
    super();
    this.column = column;
    this.stringValue = value;
  }

  public PairRule() {
    super();
  }

  @Override
  public String toString() {
    return "PairRule:" + firstString1 + ">>" + secondString2;
  }

  public boolean isParsePositive(Row row) {
    if (prevMatch) {
      boolean pos = row.getRovValue(column).equals(secondString2);
      if (pos) {
        prevMatch = false;
        this.row.setEnable();
        return true;
      }
    }
    prevMatch = row.getRovValue(column).equals(firstString1);
    if (prevMatch) {
      this.row = row;
    }
    return false;
  }

  public String getName() {
    return "PrefixRule";
  }

  @Override
  public void setVelue(String text) {
    if (firstString) {
      secondString2 = text;
    }
    else {
      firstString = true;
      firstString1 = text;
    }
  };
}
